package com.zsl.blog.api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zsl.blog.api.dao.dos.Archives;
import com.zsl.blog.api.dao.pojo.Article;
import com.zsl.blog.api.service.ArticleService;
import com.zsl.blog.api.vo.ArticleVo;
import com.zsl.blog.api.vo.Result;
import com.zsl.blog.api.vo.params.LimitParams;
import com.zsl.blog.api.vo.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javassist.compiler.MemberResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Method;
import java.util.List;

@RestController
@RequestMapping("articles")
@Api(tags = "文章")
public class ArticleController {

    @Autowired
    ArticleService articleService;
   /**
   *@Description:文章列表接口
   * @param pageParams
   *@Return:com.zsl.blog.api.vo.Result
   *@Data:2022/11/15 21:43
   *@Author:zhaosilong
   */
   @ApiOperation("文章列表")
    @PostMapping
    public Result listArticle(@RequestBody PageParams pageParams){
         Result result = articleService.listArticle(pageParams);

        return result;
    }
    /**
    *@Description:最热文章展示接口
    * @param limit
    *@Return:com.zsl.blog.api.vo.Result
    *@Data:2022/11/18 21:38
    *@Author:zhaosilong
    */
    @PostMapping("/hot")
    @ApiOperation("最热文章")
    public Result hot(){
        Integer num = 5;
       List<ArticleVo> articleList = articleService.findHotsArticles(num);
       return Result.success(articleList);
    }
    /**
    *@Description:最新文章展示接口
    *@Return:com.zsl.blog.api.vo.Result
    *@Data:2022/11/18 21:39
    *@Author:zhaosilong
    */
    @PostMapping("/new")
    @ApiOperation("最新文章")
    public Result newArtivles(){
        int limit = 5;
        List<ArticleVo> articleList = articleService.findNewArticles(limit);
        return Result.success(articleList);
    }
    /**
    *@Description:
    *@Return:com.zsl.blog.api.vo.Result
    *@Data:2022/11/18 21:48
    *@Author:zhaosilong
    */
    @PostMapping("/listArchives")
    @ApiOperation("文章归档")
    public Result listArchives(){
        List<Archives> articleList = articleService.listArchives();
        return Result.success(articleList);
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long id) {
        ArticleVo articleVo = articleService.findArticleById(id);

        return Result.success(articleVo);
    }
}
